<template>
  <el-dialog title="分配角色" :visible="showDialogRole" @close="hClose">
    <!-- 复选框 -->
    <el-checkbox-group v-model="roles">
      <el-checkbox v-for="item in roleList" :key="item.id" :label="item.id">{{ item.name }}</el-checkbox>
      <br>
      <br>

      <el-button type="primary" size="small" @click="hSave">确认</el-button>
      <el-button size="small">取消</el-button>

    </el-checkbox-group>
  </el-dialog>
</template>

<script>
import { getRolesList } from '@/api/role'
import { getEmployeeDetail, assignRoles } from '@/api/employee'
export default {
  props: {
    showDialogRole: {
      type: Boolean,
      required: true
    },
    curId: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      roleList: [], // 角色列表
      roles: []
    }
  },
  async created() {
    // 角色列表
    const res = await getRolesList()
    // console.log(res)
    this.roleList = res.data
  },
  methods: {
    // 关闭弹框
    hClose() {
      this.$emit('update:showDialogRole', false)
    },
    // 查询角色详情
    async getRoles() {
      const res = await getEmployeeDetail(this.curId)
      console.log(res.data)
      this.roles = res.data.roleIds
    },
    async hSave() {
      await assignRoles({ id: this.curId, roleIds: this.roles })
      this.hClose()
    }
  }
}
</script>

<style>

</style>
